#
#   Levels.py
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; version 2 of the License.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   Copyright
#   Author: Salvatore S. Gionfriddo
#   Contributors: Nicholas F. Hoover
#   Created: 2007.07.06
#   Last Modified: 2007.07.12
#

import Spawner

from Level import Level

class Levels:

    NUM_LEVELS = 10
    
    (NAME, GOAL_TYPE, GOAL, LEVEL_BONUS, DESCRIPTION, SPAWNERS) = range(6)
    
    (SPAWNER_TYPE, SPAWNER_ARGS, SPAWN_FUNCTION, SPAWN_TICK) = range(4)
    
    LEVELS = range(NUM_LEVELS)
    
    
    ##########################################
    # Intro: Kill a kid                      #
    # Level One: Kill 10 kids                #
    # Level Two: Eat 30 kids                 #
    # Level Three: Kill 40 kids with kicks   #
    # Level Four: Kill 50 kids with flame    #
    # Level Five: Kill 100 kids              #
    # Level Six: Kill 50 kids                #
    # Level Seven: Kill 150 kids             #
    ##########################################
        
    LEVELS[0] = ["Intro", "Kills", 1, 0,
                 ["Go on a walk. If anyone bothers you, press 's' to quickly punch them."
                  "",
                  "HINT: Punches are very fast and can kill up to 2 kids at the same time.",
                  "      They will hit kids between your body and your extended fist."],
                 
                 [["Linear", [.1, 1, 0, 90], "Kid", "Kills"]]]
    
    LEVELS[1] = ["One", "Kills", 10, 1000,
                 ["You had to kill him didn't you? No self control. Now the hunger won't end.",
                  "",
                  "Your hunger meter is always decreasing, if it drops all the way to starving, your",
                  "health will start dropping also.",
                  "Maybe some food will show up in the next level.",
                  "Check the upper right corner of the screen to see how close you are to the goal."],
                 
                 [["Linear", [.2, 2, 0, 90], "Kid", "Kills"]]]
    
    LEVELS[2] = ["Two", "Eaten", 10, 10000,
                 ["Getting hungry aren't you? I bet those dead kids are edible! Eat 10 Dead Kids",
                  "Press the spacebar to bend over and eat up to 3 Dead Kids and/or Pizza.",
                  "Line up your front foot with what you want to pick up.",
                  "",
                  "HINT: Dead Kids refill your health and decreases your hunger a little bit each.",
                  "      Pizza fills up your hunger meter by a lot."],
                 
                 [["Linear", [.2, 2, 0, 60], "Kid", "Kills"],
                  ["StatBurst",[0,1], "Pizza", "Kills"]]]
    
    LEVELS[3] = ["Three", "KillsByKick", 15, 1000,
                 ["Lets see some variety in your attacks. Kick those little brats by pressing 'd'.",
                  "Kill 15 Kids with a kicks.",
                  "",
                  "HINT: Kicks are slower than punches but can take out up to 7 kids at a time.",
                  "      They will hit kids along your leg out to and around your foot.",
                  "",
                  "Remember to keep eating."],
                 
                 [["Linear", [.2, 2, 0, 90], "Kid", "Kills"],
                  ["Random", [], "Kid", "Kills"]]]

    
    LEVELS[4] = ["Four", "KillsByFlame", 50, 1000,
                 ["Heartburn time! Bring on the pain, bring on the flame! Take down 50 kids with a Flame Attacks.",
                  "",
                  "When you're hunger meter fills to the point where you are full, you start getting heartburn.",
                  "Instead of taking some antacid, why not just press 'a' to burp up some flames?",
                  "The Flame Attack is super powerful, scorching all that stand in its path. However, everytime",
                  "you perform this attack, your hunger meter decreases, so be carful not to flame too much.",
                  "",
                  "HINT: Heartburn will stay around as long as you keep from being hungry. If you start",
                  "      dropping into the 'Almost Full' range, better pick something up quick.",
                  "      In addition to dead kids and Pizza, you can pick up a bowl of Spicy Indian Food which",
                  "      will give you unlimited Heartburn for a few seconds. If you pick one of these up, blow",
                  "      away, but be careful not to let your hunger meter drop too low.",
                  "",
                  "Just keep eating!"],
                 
                 [["Triangle", [.2, 2, 25], "Kid", "KillsByFlame"],
                  ["StatBurst", [0,1], "Indian", "Kills"],
                  ["StatBurst", [10,1],"Pizza", "Kills"],
                  ["StatBurst", [20,1],"Indian", "Kills"],
                  ["StatBurst", [35,1],"Pizza", "Kills"],]]

                 
    LEVELS[5] = ["Five", "Kills", 80, 1000,
                 ["That's all the attacks you've got. Lets see if you've go the skils to kill 80 kids.",
                  "If you're health is really low, try eating some drugs. They'll give you a small boost right",
                  "away, but then do some damage. After a little bit, they will restore your health to maximum",
                  "",
                  "HINT: Be careful not to take drugs when your health is very low. They might kill you!",
                  "      Try to eat a few dead kids first to raise your health before."],
                 
                 [["Triangle", [.3, 5, 40], "Kid", "Kills"],
                  ["StatBurst", [0,1], "Drugs", "Kills"],
                  ["Random", [], "Drugs", "KillsByFlame"],
                  ["Random", [], "Indian", "KillsByFlame"]]]

    LEVELS[6] = ["Six", "Kills", 50, 1000,
                 ["Can you survive a mobbing?",
                  "",
                  "HINT: Line 'em up and knock 'em down"],
                 
                 [["StatBurst", [0,50], "Kid", "Kills"]]]
    
    LEVELS[7] = ["Seven", "Kills", 50, 1000,
                 ["Are they getting faster?",
                  "",
                  "HINT: Watch out for the blonde ones."],
                 
                 [["Linear", [.2, 2], "Kid", "Kills"],
                  ["Linear", [.1, 2], "FastKid", "Kills"],
                  ["Random", [.1, .1], "Pizza", "KillsByPunch"],
                  ["Random", [.1, .1], "Drugs", "KillsByPunch"]]]
    
    LEVELS[8] = ["Eight", "Kills", 150, 1000,
                 ["You're a champ! See if you can get 150 kills. Good Luck!",],
                 [["Linear", [.3, 2],"FastKid", "Kills"],
                  ["Linear", [.2, 2],"Kid", "Kills"]]]

    LEVELS[9] = ["Nine", "Kills", 1000, 1000,
                 ["What!?!? How did you even get here???. Fine. Try to kill 1000."],
                 [["Linear", [.5, 2, -1, 60], "FastKid", "Kills"]]]               
                    
    GOAL_DESCRIPTIONS = {"Kills": "More Kills", "KillsByPunch": "More Kills By Punch",
                         "KillsByKick": "More Kills By Kick", "KillsByFlame": "More Kills By Flame",
                         "Eaten": "Kids To Eat"}

    def __init__(self, statTrackers, spawnFunctions):
        self.levels = range(Levels.NUM_LEVELS)
        self.statTrackers = statTrackers
        self.spawnFunctions = spawnFunctions
        self.loadLevels()
        
    def loadLevels(self):
        i = 0
        for level in Levels.LEVELS:
            goalStatTracker = self.statTrackers[level[Levels.GOAL_TYPE]]
            self.levels[i] = Level(level[Levels.GOAL], goalStatTracker, level[Levels.LEVEL_BONUS], level[Levels.DESCRIPTION])
            self.levels[i].goalType = Levels.GOAL_DESCRIPTIONS[level[Levels.GOAL_TYPE]]
            for spawner in level[Levels.SPAWNERS]:
                spawnerFunction = self.spawnFunctions[spawner[Levels.SPAWN_FUNCTION]]
                spawnerArgs = spawner[Levels.SPAWNER_ARGS]
                statTracker = self.statTrackers[spawner[Levels.SPAWN_TICK]]
                if spawnerArgs != []:
                    spawner_obj = Spawner.__dict__[spawner[Levels.SPAWNER_TYPE]+'Spawner'](spawnerFunction, statTracker, *spawnerArgs)
                else:
                    spawner_obj = Spawner.__dict__[spawner[Levels.SPAWNER_TYPE]+'Spawner'](spawnerFunction, statTracker)
                self.levels[i].addSpawner(spawner_obj)
            i += 1
        
    def getLevels(self):
        return self.levels
